package com.changgou;

import com.changgou.util.IdWorker;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import tk.mybatis.spring.annotation.MapperScan;

@SpringBootApplication
@EnableEurekaClient
@MapperScan(basePackages = {"com.changgou.goods.dao"})
@ComponentScan(basePackages={"com.changgou"})//扫描swagger配置
@EnableSwagger2
public class GoodsApplication {
    public static void main(String[] args) {
        SpringApplication.run( GoodsApplication.class,args);
    }


    /**
     * @Bean注解表示把当前对象注入到spring容器中，然后spring容器替我们完成对象的实例化
     *
     * 为什么要在入口类中把IdWorker注入到spring容器中？
     *
     * ​	想要的目的是在执行调用Idworker的时候是用@Autowired注解来进行调用
     *
     * @Autowired注解表示从spring容器中自动扫描实例
     */

    @Value("${workerId}")
    private Integer workerId;

    @Value("${datacenterId}")
    private Integer datacenterId;
    //把idworker注入到spring的容器中
    @Bean
    public IdWorker idWorker(){
        return new IdWorker(workerId,datacenterId);
    }
}
